from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import orm
import model
#from src.model import OrderLine
orm.start_mappers()
engine = create_engine('sqlite:///test.db')
Session = sessionmaker(bind=engine)
# 创建Session类实例
session = Session()

def create_database():
    orm.metadata.create_all(engine)

def test_orderline_mapper_can_load_lines(session):
    session.execute("delete from order_lines")
    print("11111")
    session.execute(
        "INSERT INTO order_lines (orderid, sku, qty) VALUES "
        '("order1", "RED-CHAIR", 12),'
        '("order1", "RED-TABLE", 13),'
        '("order2", "BLUE-LIPSTICK", 14)'
    )
    print(model.OrderLine)
    expected =[
        model.OrderLine("order1", "RED-CHAIR",12),
        model.OrderLine("order1", "RED-TABLE", 13),
        model.OrderLine("order2", "BLUE-LIPSTICK", 14),
    ]
    print(expected)
    #session.commit()
    assert session.query(model.OrderLine).all() == expected

if __name__ == "__main__":
    #test_orderline_mapper_can_load_lines(session)
    #a = model.OrderLine("order1", "RED-CHAIR", 12)
    #print(a)
    print("俊杰" in "林俊杰")